<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>菜单添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
    <link rel="stylesheet" href="/static/system/css/font.css">
    <link rel="stylesheet" href="/static/system/css/xadmin.css">
    <script type="text/javascript" src="/static/system/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/system/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
            <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label for="m_name" class="layui-form-label">
                        <span class="x-red">*</span>菜单名称</label>
                    <div class="layui-input-inline">
                        <input type="text" id="m_name" name="m_name" lay-verify="required" maxlength="20"
                            autocomplete="off" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>不能为空
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="icon" class="layui-form-label">
                        <span class="x-red">*</span>图标</label>
                    <div class="layui-input-inline">
                        {if $pid == 0}
                        <input type="text" id="icon" name="icon" lay-verify="required" maxlength="20"
                            autocomplete="off" class="layui-input">
                        {else}
                        <input type="text" id="icon" name="icon" lay-verify="required" maxlength="20"
                            autocomplete="off" class="layui-input" value="--" disabled>
                        {/if}
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span><a class="layui-word-aux" href="/static/system/pages/icon.html" target="_blank">点击查看图标参考</a>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="mca_url" class="layui-form-label">
                        <span class="x-red">*</span>mca_url</label>
                    <div class="layui-input-inline">
                        {if $pid == 0}
                        <input type="text" id="mca_url" name="mca_url" lay-verify="required" maxlength="80"
                            autocomplete="off" class="layui-input" value="--" disabled>
                        {else}
                        <input type="text" id="mca_url" name="mca_url" lay-verify="required" maxlength="80"
                            autocomplete="off" class="layui-input">
                        {/if}
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>模块/控制器/方法
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="sort" class="layui-form-label">
                        <span class="x-red">*</span>排序</label>
                    <div class="layui-input-inline">
                        <input type="text" id="sort" name="sort" lay-verify="required" maxlength="11" autocomplete="off"
                            class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">
                        <span class="x-red">*</span>顶级1位数，二级2位数，三级3位数
                    </div>
                </div>
                <input type="hidden" name="pid" value="{$pid}">
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button class="layui-btn" lay-filter="save" lay-submit="">确定</button>
                </div>
            </form>
        </div>
    </div>
    <script>
        layui.use(['form', 'layer', 'jquery'],
            function () {
                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer;

                //监听提交
                form.on('submit(save)', function (data) {
                    console.log(data);
                    //发异步，把数据提交给php
                    $.ajax({
                        url: "{:url('menuAdd')}",
                        type: "POST",
                        data: data.field,
                        success: function (res) {
                            if (res.code == 0) {
                                layer.msg(res.msg, { icon: 1, time: 1000 }, function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.location.reload(); //刷新父页面
                                    parent.layer.close(index);
                                });
                            } else {
                                layer.alert(res.msg, { icon: 6 });
                            }
                        }
                    });
                    return false; // 一定要加这个

                });

            });

    </script>
</body>

</html>